package LeetCode;

public class LC_263_UglyNumber {

    public static void main(String[] args) {

    }

    static class Solution {
        public boolean isUgly(int num) {
            if (num < 1) return false;
            boolean isPrime = true;
            for (int i = 2; i <= Math.sqrt(num); i++) {
                if (i > 5) {
                    return false;
                } else if (num % i == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) return num <= 5;
            for (int i = 2; i <= num; i++) {
                if (i > 5) {
                    return false;
                } else if (num % i == 0) {
                    num /= i;
                    i--;
                }
            }
            return true;
        }

    }

    static class Solution_2 {
        public boolean isUgly(int num) {
            if (num <= 0) return false;
            while (num % 2 == 0) num /= 2;
            while (num % 3 == 0) num /= 3;
            while (num % 5 == 0) num /= 5;
            return num == 1;
        }

    }
}